package m1;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListener;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.message.MessageExt;

import java.util.List;

/**
 * @description:
 * @author: LiuXingYu
 * @date: 2021/9/24 16:36
 */
public class Consumer1 {

    public static void main(String[] args) throws MQClientException {

        DefaultMQPushConsumer c = new DefaultMQPushConsumer("cons-group1");

        c.setNamesrvAddr("192.168.64.141:9876");

        c.subscribe("topic1", "TagA || TagB || TagC");

        c.setMessageListener(new MessageListenerConcurrently() {
            @Override
            public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
                for (MessageExt message : list) {
                    String s = new String(message.getBody());
                    System.out.println("收到: " + s);
                }
                return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
//                return ConsumeConcurrentlyStatus.RECONSUME_LATER; // 稍后重新消费
            }
        });

        c.start();
    }
}
